package com.fengzhi.web.dao.core.impl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import com.fengzhi.web.dao.core.IGenericDao;

public class GenericDaoImpl<T> extends BasicDaoImpl implements IGenericDao<T> {
	protected Class<T> entityClass;
	protected String className;

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public GenericDaoImpl() {
		this.entityClass = null;
		Class c = getClass();
		Type t = c.getGenericSuperclass();
		if (t instanceof ParameterizedType) {
			Type[] p = ((ParameterizedType) t).getActualTypeArguments();
			this.entityClass = (Class<T>) p[0];

			this.className = entityClass.getName();
		}
	}

	@Override
	public T getById(Serializable id) {
		log.info("根据id获取实体对象");
		return this.getById(entityClass, id);
	}

}
